package com.itheima.design.mode.cglib_proxy;


import net.sf.cglib.proxy.Enhancer;

public class Play {

    public static void main(String[] args) {

        //创建Enhancer对象用来生成代理类
        Enhancer e = new Enhancer();
        //创建需要被代理的类TeacherCang
        Girl tc = new TeacherCang();

        //设置增强回调
        e.setCallback(new MyMethodInterceptor(tc));

        System.out.println("-----------对接口生成代理对象--------------");
        e.setInterfaces(new Class[]{Girl.class});

        //生成代理的接口的动态代理对象
        Girl girl = (Girl)e.create();

        //调用被代理的接口的dating方法
        girl.dating(1.8f);


        System.out.println("-----------对类生成代理对象--------------");
        e.setSuperclass(TeacherCang.class);
        //把前面的设置的接口Girl置为空
        e.setInterfaces(null);
        //生成代理的类TeacherCang的动态代理对象
        TeacherCang proxy = (TeacherCang) e.create();
        //调用代理的类TeacherCang的dating方法
        proxy.dating(1.8f);

    }
}
